<template>
	<view class="patientList-wrap">
		<view class="patientList-box">
			<u-title value="患者档案"></u-title>
			<view class="patientList-list">
				
				<view class="patientList-item" v-for="(item, index) in dataList" :key="index" >
					<view class="patientList-item-layer" @click="selectPatient(item.id)" >
						<view class="patientList-item-top">
							<view class="patientList-item-name">{{item.patientName}}</view>
							<view class="patientList-item-sex">{{ rangeSex[item.sex].text}}&nbsp;&nbsp;&nbsp;{{item.age}}岁</view>
						</view>
						<view class="patientList-item-bottom">
							<view class="patientList-item-cardid">{{item.idNum}}</view>
							<view class="patientList-item-phone">{{item.phone}}</view>
						</view>
					</view> 

					<image @click.stop="gotoRouter('/pages-member/patientInfo/patientInfo?id='+item.id)" class="patientList-item-img" src="http://k8s.vendingtech.vip/images/updates@2x.png"></image>
				</view>
				
				
			</view>

			<view class="patientList-section" @click.stop="gotoRouter('/pages-member/patientInfo/patientInfo')">
				<image src="http://k8s.vendingtech.vip/images/plus@2x.png" class="patientList-section-icon"></image>
				<view class="patientList-section-word">添加患者</view>
			</view>
		</view>

		<!-- <u-bottom-button v-if="pageType==2" value="添加药品" @click="gotoRouter('/pages-inquiry/selectDrug/selectDrug')"></u-bottom-button>
		<u-bottom-button v-if="pageType&&pageType!=2" value="下一步" @click="gotoRouter('/pages-inquiry/selectDrug/selectDrug')"></u-bottom-button> -->
	</view>
</template>

<script>
import uBottomButton from '@/components/u-bottom-button/u-bottom-button.vue';
import uTitle from '@/components/u-title/u-title.vue';
import { mapState, mapMutations } from 'vuex';
import { startEid } from '@/mp_ecard_sdk/main'
export default {
	components: {
		uBottomButton,
		uTitle
	},
	data() {
		return {
			pageType: null,// null展示模式  0-2选择模式
			dataList: null
		};
	},
	computed: {
		...mapState({
			questionOrderForm: state => state.questionOrderForm
		})
	},
	onLoad(option) {
		this.pageType = option.type ? option.type : null;
	},
	onShow() {
		this.patientList()
	},
	methods: {
		...mapMutations({
			setQuestionOrderForm: 'setQuestionOrderForm',
			clearQuestionOrderForm: 'clearQuestionOrderForm'
		}),
		//患者列表
		patientList() {
			this.$api
				.patientList({})
				.then(res => {
					if (res.code == 200) {
						this.dataList = res.result
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				});
		},
		
		//选择患者
		selectPatient(id){
			if(this.pageType){
				this.questionOrderForm.patientId = id
				this.setQuestionOrderForm(this.questionOrderForm);
				
				if(this.pageType==2){
					this.gotoRouter("/pages-inquiry/selectDrug/selectDrug");
				}else{
					this.onFace(id)
					// this.gotoRouter("/pages-inquiry/inquiryPayment/inquiryPayment");
				}
				
			}
		},
		onFace(id){
			let _this = this
			this.$api.patientDetectAuth({
				id: id
			}).then(res1 => {
				startEid({
					data: {
						token: res1.result.eidToken,
					},
					verifyDoneCallback(res2) {
						const { token, verifyDone } = res2;
						console.log(res2,'？？？？？？？？？？？')
						
						_this.$api.patientDetectAuthResult({
							eidToken: token,
							id: id
						}).then(res3 => {
							if(res3.result){
								_this.gotoRouter("/pages-inquiry/inquiryPayment/inquiryPayment");
							}else{
								uni.showModal({
									title: '提示',
									content: '身份匹配失败',
									showCancel: false,
									success: res => {}
								})
								// uni.showToast({
								// 	title: '身份匹配失败',
								// 	icon: 'none'
								// });
							}
							// if (res3.code == 200 && res3.result.text && res3.result.text.errCode == 0) {
							// 	 _this.gotoRouter("/pages-inquiry/inquiryPayment/inquiryPayment");
							// }else{
							// 	uni.showToast({
							// 		title: '身份匹配失败',
							// 		icon: 'none'
							// 	});
							// }
						}); 
						
					},
				});
			});
		}
	}
};
</script>

<style lang="less">
@import './patientList.less';
</style>
